/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commande.modeles.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlTransient;
import client.modeles.entity.Client;

/**
 *
 * @author MAZID
 */
@Entity
public class Commande implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "numCom")
    private Integer numCom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "totalHT")
    private float totalHT;
    @Basic(optional = false)
    @NotNull
    @Column(name = "totalTTC")
    private float totalTTC;
    @Basic(optional = false)
    @NotNull
    @Column(name = "dateCom")
    // TIMESTAMP: les dates des commandes seront créer automatiquement par le systeme
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "estLivree")
    private boolean estLivree;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "commande", fetch = FetchType.EAGER)
    private Collection<Lignecommande> lignecommandes;
    
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Client client;

    public Commande() {
    }

    public Commande(Integer numCom) {
        this.numCom = numCom;
    }

    public Commande(Integer numCom, float totalHT, float totalTTC, Date dateCom, boolean estLivree) {
        this.numCom = numCom;
        this.totalHT = totalHT;
        this.totalTTC = totalTTC;
        this.dateCom = dateCom;
        this.estLivree = estLivree;
    }

    public Integer getNumCom() {
        return numCom;
    }

    public void setNumCom(Integer numCom) {
        this.numCom = numCom;
    }

    public float getTotalHT() {
        return totalHT;
    }

    public void setTotalHT(float totalHT) {
        this.totalHT = totalHT;
    }

    public float getTotalTTC() {
        return totalTTC;
    }

    public void setTotalTTC(float totalTTC) {
        this.totalTTC = totalTTC;
    }

    public Date getDateCom() {
        return dateCom;
    }

    public void setDateCom(Date dateCom) {
        this.dateCom = dateCom;
    }

    public boolean getEstLivree() {
        return estLivree;
    }

    public void setEstLivree(boolean estLivree) {
        this.estLivree = estLivree;
    }

    @XmlTransient
    public Collection<Lignecommande> getLignecommandes() {
        return lignecommandes;
    }

    public void setLignecommandes(Collection<Lignecommande> lignecommandes) {
        this.lignecommandes = lignecommandes;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numCom != null ? numCom.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commande)) {
            return false;
        }
        Commande other = (Commande) object;
        if ((this.numCom == null && other.numCom != null) || (this.numCom != null && !this.numCom.equals(other.numCom))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "commande.modeles.entity.Commande[ numCom=" + numCom + " ]";
    }
    
}
